<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑分类</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/themes/admin/css/font.css">
    <link rel="stylesheet" href="/themes/admin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/themes/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/themes/admin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">分类名</label>
                            <div class="layui-input-inline">
                                <input type="text" value="{$cateDetail.cate_name|default=''}" name="cate_name"  required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">*必填</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">封面</label>
                            <div class="layui-input-inline">
                              <img id="cate-cover" style="width: 200px;height: 200px" src="{$cateDetail.cover_image|default='/static/images/api/default_cate_cover.jpg'}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button id="btn-submit" class="layui-btn" lay-submit lay-filter="updateCate">提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;

        //分类封面上传
        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#cate-cover'
                ,url: '/admin/article/upload?id={$cateDetail.cate_id}'
                ,auto: false
                ,accept:'images'
                ,field:'Image'
                ,bindAction: '#btn-submit'
                ,choose: function(obj){
                    obj.preview(function(index, file, result){
                        $("#cate-cover").attr("src",result);
                    });
                }
                ,done:function(res){
                    if(res.code == 0){
                        layer.msg(res.msg,{icon:2});
                    }
                }
            });
        });

        //监听提交
        form.on('submit(updateCate)', function(data){
            $.ajax({
                type:"POST",
                data:data.field,
                url:"/admin/article/updateCate?cate_id={$Request.get.cate_id}",
                success:function (e) {
                    if (e.code == 1){
                        layer.msg(e.msg)
                        setTimeout(function () {
                            parent.location.reload();
                        },1000)
                    }else{
                        layer.msg(e.msg)
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>